import type { FileUploadDto, FileDeleteDto, PresignedUploadUrlDto, ResponseDto } from '@/types/api';
import request from '@/utils/request';

// 文件管理API
export const fileApi = {
  // 文件上传
  uploadFile: async (data: FileUploadDto): Promise<ResponseDto> => {
    return await request.post('/app/files/upload', data, {
      headers: { 'Content-Type': 'multipart/form-data' }
    });
  },

  // 文件下载
  downloadFile: async (fileId: string): Promise<Blob> => {
    return await request.get('/app/files/download', {
      params: { id: fileId },
      responseType: 'blob'
    });
  },

  // 删除文件
  deleteFile: async (data: FileDeleteDto): Promise<void> => {
    return await request.post('/app/files/delete', data);
  },

  // 获取预签名上传URL
  getPresignedUploadUrl: async (data: PresignedUploadUrlDto): Promise<ResponseDto> => {
    return await request.post('/app/files/presigned-upload-url', data);
  }
};
